App Open
warning
This is the documentation for the Advanced API. Most developers should use our Simplified API (documented in App Open), which comes with several built-in features such as:
- Automatic ad loading
- Retries for failed requests
- Simplified lifecycle management
Only use the Advanced API if you need fine-grained control over the ad loading and presentation lifecycle.
Note: The Advanced API is only available in Swift. For Objective-C, please use the Simplified API.
The Advanced API provides direct access to individual AppOpen
instances, giving you complete control over when and how ads are loaded and displayed.
Create an AppOpen instance
let appOpen = AppOpen.create(placementId: "<placement-id>")
Register ad callbacks
// Assign a delegate to handle the ad callbacks
appOpen.delegate = self
// [...]
// Load Callbacks
func didCompletePrebidding(result: PrebiddingResults) {
print("App Open client-side bidding finished!")
}
func didLoad(result: LoadResult) {
print("App Open loaded!")
}
func failedToLoad(result: LoadResult?, error: LoadError) {
print("App Open failed to load. Reason: \(error.localizedDescription)")
}
// Show Callbacks
func didPresent() {
print("App Open is being presented!")
}
func failedToPresent(error: PresentError) {
// If you need to resume your app's flow, make sure to do it here and in the didDismiss callback
print("App Open failed to present. Reason: \(error.localizedDescription)")
}
func willDismiss() {
print("App Open will be dismissed!")
}
func didDismiss() {
// If you need to resume your app's flow, make sure to do it here and in the failedToPresent callback
print("App Open was dismissed!")
}
func didClick() {
print("App Open was clicked!")
}
func didRecordImpression(data: ImpressionData) {
print("App Open impression, with revenue: \(data.revenue)")
}
Load an ad
appOpen.load()
Load an ad (with custom properties)
var properties = CustomProperties()
properties.addString(key: "game_mode", value: "classic")
appOpen.load(customProperties: properties)
Present an ad
if appOpen.isReady {
appOpen.present(fromViewController: self, fromAdSpace: "app-open-ad-space")
}
Complete example
AppOpenAdvancedViewController.swift
import UIKit
import XMediator
class AppOpenAdvancedViewController: UIViewController {
private var appOpen: AppOpen?
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func loadButtonTouchUpInside(_ sender: Any) {
let appOpen = AppOpen.create(placementId: "<placement-id>")
appOpen.delegate = self
appOpen.load()
self.appOpen = appOpen
}
@IBAction func presentButtonTouchUpInside(_ sender: Any) {
if let appOpen = appOpen, appOpen.isReady {
appOpen.present(fromViewController: self)
}
}
}
extension AppOpenAdvancedViewController: AppOpenDelegate {
// Load Callbacks
func didCompletePrebidding(result: PrebiddingResults) {
print("App Open client-side bidding finished!")
}
func didLoad(result: LoadResult) {
print("App Open loaded!")
}
func failedToLoad(result: LoadResult?, error: LoadError) {
print("App Open failed to load. Reason: \(error.localizedDescription)")
}
// Present Callbacks
func didPresent() {
print("App Open is being presented!")
}
func failedToPresent(error: PresentError) {
// If you need to resume your app's flow, make sure to do it here and in the didDismiss callback
print("App Open failed to present. Reason: \(error.localizedDescription)")
}
func willDismiss() {
print("App Open will be dismissed!")
}
func didDismiss() {
// If you need to resume your app's flow, make sure to do it here and in the failedToPresent callback
print("App Open was dismissed!")
}
func didClick() {
print("App Open was clicked!")
}
func didRecordImpression(data: ImpressionData) {
print("App Open impression, with revenue: \(data.revenue)")
}
}